# Kexilo权限管理系统构建脚本

.PHONY: help build test clean dev prod docker k8s

# 默认目标
help:
	@echo "Kexilo权限管理系统构建脚本"
	@echo ""
	@echo "可用目标:"
	@echo "  help      显示帮助信息"
	@echo "  build     构建应用"
	@echo "  test      运行测试"
	@echo "  clean     清理构建文件"
	@echo "  dev       启动开发环境"
	@echo "  prod      生产环境部署"
	@echo "  docker    构建Docker镜像"
	@echo "  k8s       部署到Kubernetes"

# 构建应用
build:
	@echo "构建后端应用..."
	cd backend && mvn clean package -DskipTests
	@echo "构建前端应用..."
	cd frontend && npm ci && npm run build
	@echo "构建完成!"

# 运行测试
test:
	@echo "运行后端测试..."
	cd backend && mvn test
	@echo "运行前端测试..."
	cd frontend && npm test
	@echo "测试完成!"

# 清理构建文件
clean:
	@echo "清理后端构建文件..."
	cd backend && mvn clean
	@echo "清理前端构建文件..."
	cd frontend && rm -rf dist node_modules
	@echo "清理完成!"

# 启动开发环境
dev:
	@echo "启动开发环境..."
	docker-compose -f config/docker/docker-compose.yml up -d postgres redis rabbitmq
	@echo "等待数据库启动..."
	sleep 10
	@echo "开发环境已启动，可以启动应用进行开发"

# 生产环境部署
prod:
	@echo "部署生产环境..."
	docker-compose -f config/docker/docker-compose.prod.yml up -d
	@echo "生产环境部署完成!"

# 构建Docker镜像
docker:
	@echo "构建Docker镜像..."
	docker build -t kexilo/app:latest -f config/docker/Dockerfile .
	@echo "Docker镜像构建完成!"

# 部署到Kubernetes
k8s:
	@echo "部署到Kubernetes..."
	kubectl apply -f config/k8s/
	@echo "Kubernetes部署完成!"

# 数据库迁移
db-migrate:
	@echo "执行数据库迁移..."
	cd backend && mvn flyway:migrate
	@echo "数据库迁移完成!"

# 代码质量检查
quality:
	@echo "执行代码质量检查..."
	cd backend && mvn spotbugs:check
	cd frontend && npm run lint
	@echo "代码质量检查完成!"

# 安全扫描
security:
	@echo "执行安全扫描..."
	cd backend && mvn org.owasp:dependency-check-maven:check
	cd frontend && npm audit
	@echo "安全扫描完成!"

# 性能测试
perf:
	@echo "执行性能测试..."
	# 这里可以添加JMeter或其他性能测试工具的命令
	@echo "性能测试完成!"

# 停止所有服务
stop:
	@echo "停止开发环境服务..."
	docker-compose -f config/docker/docker-compose.yml down
	@echo "停止生产环境服务..."
	docker-compose -f config/docker/docker-compose.prod.yml down
	@echo "所有服务已停止!"
